﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_Bulletin_Add : System.Web.UI.Page
{
    public int BulletinID
    {
        get { return DongDong.Common.Misc.ConvertToInt(ViewState["BulletinID"]); }
        set { ViewState["BulletinID"] = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BulletinID = DongDong.Common.Misc.GetQueryStringAsInt("BulletinID");
            if (BulletinID != 0)
            {
                GetBulletinInfo();
            }

        }
    }
    protected void BtnTiJiao_Click(object sender, EventArgs e)
    {
        Bulletin objBulletin = new Bulletin();
        if (BulletinID != 0)
        {
            objBulletin = Bulletin.Get(BulletinID);
        }
        string Mess = txtNeiRong.Text;
        if (string.IsNullOrEmpty(Mess))
        {
            DongDong.Common.MessageBox.Show(this, "请输入发送内容");
            return;
        }
        else if (Mess.Length > 800)
        {
            DongDong.Common.MessageBox.Show(this, "发送内容太长");
            return;
        }
        Mess = DongDong.Common.Misc.ReplaceStript(Mess);

        objBulletin.Detail = Mess;
        objBulletin.Title = txtTitle.Text;
        if (BulletinID == 0)
        {
           
            objBulletin.AddTime = System.DateTime.Now;
            objBulletin.Rank = System.DateTime.Now;
            objBulletin.Type = (int)Bulletin.type.前台;
            objBulletin.Add();
            litMessage.Text = "公告发布成功";
            txtNeiRong.Text = "";
            txtTitle.Text = "";
        }
        else
        {
            objBulletin.Update();
            litMessage.Text = "公告更新成功";
            txtNeiRong.Text = "";
            txtTitle.Text = "";
        }

    }

    public void GetBulletinInfo()
    {
        Bulletin objBulletin = Bulletin.Get(BulletinID);
        if (objBulletin != null)
        {
            txtTitle.Text = objBulletin.Title;
            txtNeiRong.Text = objBulletin.Detail;
        }
    }
  
}